package com.baizhi.springboot.service.impl;

import com.baizhi.springboot.dao.InformDao;
import com.baizhi.springboot.entity.Inform;
import com.baizhi.springboot.service.InformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class InformServiceImpl implements InformService {
    @Autowired
    private InformDao informDao;

    @Override
    public Map selectInformByPage(Integer page, Integer limit) {
        Integer offset=(page-1)*limit;
        List<Inform> informs = informDao.selectInformByPage(offset, limit);
        Integer count = informDao.selectCount();
        /* "code": 0,
          "msg": "",
          "count": 1000,
          "data": [{}, {}]*/
        HashMap<Object, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", count);
        map.put("data", informs);
        return map;
    }

    @Override
    public void insertInform(Inform inform) {
        informDao.insertInform(inform);
    }

    @Override
    public void deleteInform(Integer id) {
        informDao.deleteInform(id);
    }

    @Override
    public Inform selectOneInform(Integer id) {
        return informDao.selectOneInform(id);
    }

    @Override
    public void updateInform(Inform inform) {
        informDao.updateInform(inform);
    }
}
